﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;
using Persistence.Dao;
using Domain;
using Persistence;
namespace web.manage
{
    public partial class News_Operate : adminBase
    {
        int id = DNTRequest.GetQueryInt("id", 0);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (id > 0)
                {
                    News news = Singleton<NewsDao>.Instance.GetModel(id);
                    if (news != null)
                    {
                        txtTitle.Value = news.newsTitle;
                        FCKeditor1.Value = news.newsContent;
                        ddltype.SelectedValue = news.newsType;
                    }
                }
            }
        }

      


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            News p;
            if (id > 0)
            {
                p = Singleton<NewsDao>.Instance.GetModel(id);
            }
            else
            {
                p = new News();
            }
            p.newsTitle = txtTitle.Value.Trim();
            p.newsContent = FCKeditor1.Value;
            p.newsType = ddltype.SelectedValue;
            p.addTime = DateTime.Now;
            
            if (id > 0)
            {
                Singleton<NewsDao>.Instance.Update(p);
            }
            else
            {
                Singleton<NewsDao>.Instance.Insert(p);
            }
            Message.alert("操作成功");



        }
    }
}
